import React, { Component } from "react";
import MainLayout from "../../../component/mainLayout/mainLayout";
import "./RecordDetail.scss";

class RecordDetail extends Component {
	constructor(props, ...args) {
		super(props, ...args);
		let obj = this.props.location.state;
		let comeType = this.props.match.params.comeType === "2";
		this.state = {
			comeType,
			amount: comeType ? obj.amount : obj.tradeAmt,
			order_no: comeType ? obj.tradeNumber : obj.tradeNumber,
			type: comeType ? obj.type : obj.tradeType,
			time: obj.tradeTime,
			tradeTypeLabel: comeType ? "" : obj.tradeTypeLabel, // 兼容处理小辉宝
			come_from: comeType ? obj.tradeDesc : obj.tradeDesc,
			// tradeType: obj.tradeType,
			tradeStatus: obj.tradeStatus,
			tradetypeDesc: obj.tradetypeDesc
		};
	}

	componentDidMount() {
		console.log(1, this.props.location.state);
	}

	render() {
		const _pageParams = {
			header: {
				title: "记录详情"
			},
			cacheLifecycles: this.props.cacheLifecycles,
			history: this.props.history
		};
		let tradeStatus = "";
		if (this.state.tradeStatus === "0" || this.state.tradeStatus === "000000") {
			tradeStatus = "交易成功";
		} else if (this.state.tradeStatus === "000001") {
			tradeStatus = "处理中";
		} else {
			tradeStatus = "交易失败";
		}
		const { comeType } = this.state;
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="record_detail_top_div">
					<span className="record_detail_money">
						{this.state.type === "1" || this.state.type === "3" ? "-" : "+"}
						{this.state.amount}
					</span>
					<br />
					<br />
					<span className="record_detail_result">{tradeStatus}</span>
				</div>
				<div className="record_detail_bottom_div">
					<div className="record_detail_bottom_left_div">
						<span>{this.state.comeType ? "交易流水号" : "订单号"}</span>
						<br />
						<br />
						<br />
						<span>订单类型</span>
						<br />
						<br />
						<br />
						<span>交易时间</span>
						<br />
						<br />
						<br />
						<span>交易说明</span>
					</div>
					<div className="record_detail_bottom_right_div">
						<span>{this.state.order_no}</span>
						<br />
						<br />
						<br />
						<span>
							{!comeType
								? this.state.tradeTypeLabel
								: this.state.type === "1" || this.state.type === "3"
								? "出账"
								: "入账"}
						</span>
						<br />
						<br />
						<br />
						<span>{this.state.time}</span>
						<br />
						<br />
						<br />
						<span>{this.state.come_from}</span>
					</div>
				</div>
			</MainLayout>
		);
	}
}

export default RecordDetail;
